#pragma once

#include <compl.h>

#ifndef BARE_METAL
#if defined(__unix__) || defined(WIN32)
#include <stdio.h>
/* 不会触发malloc */
#define dbg_printf(...)  fprintf(stderr, __VA_ARGS__)
#elif defined(__APPLE__)
#include <stdio.h>
#define dbg_printf(...)  printf(__VA_ARGS__)
#else
#error "should implement printf"
/* 应该手动实现printf */
#endif

/* 这些依赖要挪出去 */
#ifdef __unix__
#include <execinfo.h>
#define PRINT_BACKTRACE()	{\
	void *callfunc[8]; \
	int nptrs = backtrace(callfunc, 8);\
	char **cf = backtrace_symbols(callfunc, nptrs);\
	dbg_printf("--------fatal backtrace-----------\nat [%s:%d]:\n", __FILE__, __LINE__);\
	for (int idx = 0; idx < nptrs; idx++) dbg_printf("%s\n", cf[idx]);\
	}
#else
#define PRINT_BACKTRACE()
#endif

#endif
